$(() => {
    // 获取area_id
    let goods_id = GetQueryString('goods_id');
    const token = GetQueryString('token');
    let area_code = '';
    ajaxList(area_code);

    //N类商品详情
    function ajaxList(area_code) {
        $.ajax({
            type: "post",
            url: url,
            data: { 'method': "Plat|ngoods_detail", 'goods_id': goods_id, 'area_code': area_code },
            dataType: 'json',
            success: function(res) {
                // console.log(res);
                if (res.status == 1) {
                    let company_list = res.data.company_list;
                    let goods_info = res.data.goods_info;
                    let banner = '';
                    let html = '';

                    // 商品名称
                    $('title').html(goods_info.goods_name);

                    // 商品信息
                    $('.description').html(goods_info.description);
                    $('.goods_price').html('￥' + goods_info.goods_price);
                    $('.read_count').html('浏览量' + goods_info.read_count);
                    goods_info.pic.forEach(item => {
                        banner += `
                            <div class="swiper-slide"><img src="${item.thumb_url == '' ? '../img/banner.png' : item.thumb_url}" alt="${item.pic_name}" data-url="${item.pic_url}" class="baimg plusImg" /></div>
                        `;
                    })
                    $('.swiper-wrapper').html(banner);
                    // banner轮播
                    new Swiper('.swiper-container', {
                        autoplay: 3000,
                        // pagination: '.swiper-pagination',
                        loop: true,
                    })

                    company_list.forEach(item => {
                        html += `
                        <div class="comList">`
                        html += `<div class="comHead">
                                <div class="comHeadLeft">
                                    <img class="headImg" src="${item.company_logo == '' ? '../img/user.jpg' : item.company_logo}" alt="${item.company_name}">
                                    <div class="headlineTopChild">
                                        <p>${item.company_name}</p>`
                        if (item.level_logo != '') {
                            html += `<img src="${item.level_logo}" alt="${item.level_name}" class="userLevel"></img>`
                        }
                        html += `</div>
                                </div>
                                <p class="comHeadRight">进店</p>
                        </div>
                            <div class="comImgs">`
                        item.goods_list.forEach(goods => {
                            html += `<a href="javascript:;"><img class="comImg plusImg" data-url="${goods.goods_img}" src="${goods.goods_thumb == '' ? '../img/user.jpg' : goods.goods_thumb}" alt="商品图片"></a>`;
                        })
                        html += `</div>
                            <p class="comDesc">
                                主营：${item.main_business}
                            </p>
                            <p class="comAddr">
                                地址：${item.area_name + item.address}
                                <span>浏览量 ${item.read_count}</span>
                            </p>
                        </div>
                        `;
                    });
                    $('.comLists').html(html);
                } else if (res.status == 2) {
                    location.href = "fox://logout";
                } else {
                    alert(res.message);
                }
            }
        })
    }

    // 分享下载链接及备案信息底部
    if ($('.downLoad').length) {
        $.ajax({
            type: "post",
            url: url,
            data: { "method": "Api|share_bottom" },
            dataType: 'json',
            success: function(res) {
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    data.download.forEach(item => {
                        html += `
                <li><a href="${item.url}">${item.type_name}</a></li>
                `;
                    })
                    $('.dlLists').html(html);
                    $('.icp_info').html(data.icp_info);
                    $('.other_msg').html(data.other_msg);
                }
            }
        })
    }
})